package com.great.utils;

import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringToDate implements Converter<String, Date> {
    private static String[] patterns={"yyyy-MM-dd hh:mm:ss","yyyy-MM-dd","yyyy年MM月dd日"};

    @Override
    public Date convert(String s) {
        Date d = null;
        for (String p:patterns){
            SimpleDateFormat sdf = new SimpleDateFormat(p);
            try {
                d = sdf.parse(s);
                return d;
            } catch (ParseException e) {
                continue;
            }
        }
        return d;
    }

}
